package com.example.demo;

import javax.servlet.ServletContextListener;
import javax.servlet.ServletRequestAttributeEvent;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.DispatcherServlet;

import com.example.demo.flter.DemoFilter;
import com.example.demo.listener.DemoListener2;
import com.example.demo.listener.DemoListener3;
import com.example.demo.servlet.DemoServlet;

@SpringBootApplication
@ServletComponentScan
@EnableTransactionManagement
//@EnableScheduling
public class DemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}
	/**
	 * 注册自定义的servlet
	 * @return
	 */
//	@Bean
//	public ServletRegistrationBean getServletRegistrationBean(){
//		return new ServletRegistrationBean(new DemoServlet(), "/gaox/demo");
//	}
	/**
	 * 注册自定义的监听器
	 * @return
	 */
//	@Bean
//	public ServletListenerRegistrationBean getServletListenerRegistrationBean(){
//		return new ServletListenerRegistrationBean(new DemoListener3());
//	}
	/**
	 * 注册自定义的过滤器
	 * @return
	 */
//	@Bean
//	public FilterRegistrationBean getFilterRegistrationBean(){
//		FilterRegistrationBean registrationBean=new FilterRegistrationBean();
//		registrationBean.setFilter(new DemoFilter());
//		registrationBean.addUrlPatterns("/*");
//		return registrationBean;
//	}
//	@Bean
//	public ServletRegistrationBean dispatcherRegistration(DispatcherServlet servlet){
//		ServletRegistrationBean registrationBean=new ServletRegistrationBean(servlet);
//		registrationBean.getUrlMappings().clear();
//		registrationBean.addUrlMappings("/");
//		registrationBean.addUrlMappings("*.do");
//		return registrationBean;
//	}
//	@Bean
//	public EmbeddedServletContainerCustomizer containerCustomizer(){
//	       return new EmbeddedServletContainerCustomizer() {
//	           @Override
//	           public void customize(ConfigurableEmbeddedServletContainer container) {
//	                container.setSessionTimeout(10);//单位为S
//	          }
//	    };
//	}
}
